//
//  RegisterTwoViewController.swift
//  aj
//
//  Created by leeqb on 15/11/21.
//  Copyright © 2015年 powerlee. All rights reserved.
//

import UIKit

class LGRegisterTwoViewController: AJBaseViewController {
    var maskNum: String!
    var smsV:String!
    @IBOutlet weak var num: UITextField!
    
    @IBAction func sendAgain() {
        if maskNum.isEmpty {
            CBAlertView.shareInstance().showMsg("请输入手机号")
            return
        }
        
        CBMessage.shareInstance().showProcessing()
        AJNetworkHelper.instance.post("aj_user_reg_sms_apply", parameters: ["userTel":maskNum], success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) -> Void in
            CBAlertView.shareInstance().showMsg("发送成功")
            }, failed: { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in
                CBAlertView.shareInstance().showMsg("发送失败")
            }) { () -> Void in
                CBMessage.shareInstance().dismiss()
        }
    }

    @IBAction func nextStep(sender: UIButton) {
        let verifyCode = num.text!
        if verifyCode.isEmpty {
            CBAlertView.shareInstance().showMsg("请输入验证码")
            return
        }
        
        let params = ["userTel":maskNum, "smsCode":verifyCode]
        CBMessage.shareInstance().showProcessing()
        AJNetworkHelper.instance.post("aj_user_reg_sms_validate", parameters: params, success: { (operation: AFHTTPRequestOperation!, responseObject: AnyObject!) -> Void in
            // 请求成功
            if (responseObject["returnCode"] as? String == "000000"){
                let result = responseObject["result"]
                self.smsV = (result!!["smsValidateToken"] as? String)!
                let setPwd = LB("LGLogin", vcName: "SetPassword") as! LGSetPasswordViewController
                setPwd.token = self.smsV
                self.navigationController?.pushViewController(setPwd, animated: true)
            } else {
                CBAlertView.shareInstance().showMsg(responseObject["errorMsg"] as? String)
            }
            }, failed: { (operation: AFHTTPRequestOperation!, error: NSError!) -> Void in
                CBAlertView.shareInstance().showMsg("验证码错误，请重新输入！")
            }) { () -> Void in
                CBMessage.shareInstance().dismiss()
        }
    }
    
}
